#pragma once
#include "renderer.h"
#include "shader_catalog_cg_opengl.h"
#include "texture_catalog_opengl.h"
#include "vertex_buffer_opengl.h"
#include "index_buffer_opengl.h"

namespace krryn{
namespace system_imp{
	class renderer_opengl : public krryn::view::renderer{
	public:
		renderer_opengl();

		virtual void clear_buffers(int a_Buffers, math::color3 a_Color = math::color3(0, 0, 0), float a_Depth = 1, unsigned short a_Stencil = 0);
		virtual krryn::core::refc_ptr<view::texture_catalog> get_texture_catalog();
		virtual krryn::core::refc_ptr<view::shader_catalog> get_shader_catalog();
		virtual void set_texture(unsigned int a_Unit, bool a_Enabled, krryn::core::refc_ptr<view::texture> a_Texture);
		virtual krryn::math::matrix_stack &get_matrix_stack(view::matrix_type a_Type);
		virtual void render(view::render_operation &a_Operation);
		virtual krryn::core::refc_ptr<view::index_buffer> create_index_buffer(size_t a_NumberOfIndices, view::index_buffer_format a_Format);
		virtual krryn::core::refc_ptr<view::vertex_buffer> create_vertex_buffer(size_t a_VertexSizeInBytes, size_t a_NumberOfVertices);
		virtual krryn::core::refc_ptr<view::render_target> create_render_target(int a_Width, int a_Height);
	private:
		GLint m_MaxTextureUnits;
		GLint m_MaxBuffers;
		std::vector<krryn::math::matrix_stack> m_MatrixStacks;

		const GLvoid *map_to_vbo_offset(size_t a_OffsetInBytes);
		GLenum get_draw_mode(view::draw_mode a_Mode);
		GLint get_element_size(view::element_type a_Element);
		GLenum get_element_type(view::element_type a_Element);
	};
}
}